package vip.xumy.admin.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.admin.sys.pojo.Dictionary;

/**
 * @author:mengyxu
 * @date:2019年12月6日
 */

@Mapper
public interface IDictTypeMapper {

	@Results(id = "typeRM", value = { @Result(property = "code", column = "type_code"),
			@Result(property = "name", column = "type_name"), @Result(property = "desc", column = "type_desc"),
			@Result(property = "status", column = "type_status"),
			@Result(property = "children", column = "{parent=type_code}", javaType = List.class, many = @Many(select = "com.sprt.admin.sys.mapper.IDictionaryMapper.queryDict")) })
	@Select({ "<script>", "SELECT * FROM dict_type ", "<where>",
			"<if test='code != null'> AND type_code = #{code} </if>",
			"<if test='name != null'> AND type_name like CONCAT('%',#{name},'%') </if>",
			"<if test='status != null'> AND type_status = #{status} </if>", "</where>", "ORDER BY type_name ASC",
			"</script>" })
	List<Dictionary> queryType(Dictionary example);

	@Insert({
			"INSERT INTO dict_type (type_code, type_name, type_desc, type_status) VALUES (#{code}, #{name}, #{desc}, #{status})" })
	void insertType(Dictionary type);

	@Update({
			"UPDATE dict_type SET type_name = #{name}, type_desc = #{desc}, type_status = #{status} WHERE type_code = #{code}" })
	void updateType(Dictionary type);

	@Delete({ "DELETE FROM dict_type WHERE type_code = #{code}" })
	void deleteType(String code);

}
